function hfile = prt_SetDuration(hfile, conds, dur)
% PRT::SetDuration  - set duration(s) in conditions of a PRT
%
% FORMAT:       [prt =] prt.SetDuration(conds, dur)
%
% Input fields:
%
%       conds       1xC condition list
%       dur         duration in units of PRT
%
% Output fields:
%
%       prt         altered PRT
%
% Examples:
%
%   prt.SetDuration(2:8, 4000);
%

% Version:  v0.7g
% Build:    9072022
% Date:     Jul-20 2009, 10:55 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 3 || ...
    numel(hfile) ~= 1 || ...
   ~isBVQXfile(hfile, 'prt') || ...
   ~isa(conds, 'double') || ...
    isempty(conds) || ...
    any(isinf(conds(:)) | isnan(conds(:)) | conds(:) < 0.5) || ...
   ~isa(dur, 'double') || ...
    numel(dur) ~= 1 || ...
    isinf(dur) || ...
    isnan(dur) || ...
    dur < 0
    error( ...
        'BVQXfile:BadArgument', ...
        'Invalid call to %s.', ...
        mfilename ...
    );
end
conds = unique(round(conds(:)'));
bc = bvqxfile_getcont(hfile.L);

% get number of conditions
ncon = numel(bc.Cond);
conds(conds > ncon) = [];

for cc = conds
    bc.Cond(cc).OnOffsets(:, 2) = bc.Cond(cc).OnOffsets(:, 1) + dur;
end

% set new content
bvqxfile_setcont(hfile.L, bc);
